Skip to content

fix(metadata): drop unreachable array guards on serializer attributes - #8460

Merged
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/metadata-dead-serializer-attribute-guards
Aug 16, 2026
Merged

fix(metadata): drop unreachable array guards on serializer attributes#8460
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/metadata-dead-serializer-attribute-guards

Conversation

@soyuka

@soyuka soyuka commented Aug 16, 2026

Copy link
Copy Markdown
Member

One of three PRs finishing the 4.3 CI unblock started in #8458. Pure dead-code removal, no behaviour change.

PHPStan (PHP 8.5) fails on 4.3 with:

src/Metadata/Property/Factory/SerializerPropertyMetadataFactory.php
  61  Call to function is_array() with non-empty-array will always evaluate to true.
  65  Call to function is_array() with non-empty-array will always evaluate to true.

getEffectiveSerializerAttributes() (:239-278) is declared @return (array|null)[] and every return path yields array|null, so the !\is_array() branches could never execute. Introduced by copy-paste in 64b46b2d0 (#7629), where attributes support was cloned from the groups block above.

Why the sibling guards are left alone

The structurally identical guards for $normalizationGroups / $denormalizationGroups a few lines up do not error, and that asymmetry is correct rather than an oversight:

  • getEffectiveSerializerGroups() returns (string[]|string|null)[] — the string member keeps !is_array() reachable.
  • It is grounded in Symfony's contract, not just our docblocks. AbstractNormalizer::getGroups() does \is_scalar($groups) ? (array) $groups : $groups, explicitly supporting a scalar groups. AbstractNormalizer::isAllowedAttribute() has no equivalent coercion for ATTRIBUTES; a non-array simply falls through to return true.

So attributes is array-only by Symfony's own contract. Coercing a scalar here would make this factory diverge from the serializer that consumes the value.

getEffectiveSerializerAttributes() always returns array|null, so the !is_array()
branches could never run. Unlike serializer groups, Symfony's AbstractNormalizer
does not coerce a scalar "attributes" context, so there is no string form to
normalise here.
@soyuka
soyuka merged commit e22463f into api-platform:4.3 Aug 16, 2026
104 of 112 checks passed
@soyuka
soyuka deleted the fix/metadata-dead-serializer-attribute-guards branch August 16, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant